#ifndef __DEBUG_H__
#define __DEBUG_H__
#include "type.h"
#include "drv.h"

#define PRINTF_DSP  1

#if PRINTF_DSP
#include "stdio.h"
#else
#include <stdarg.h>
extern void xprintf (const char* fmt, ...);

#define printf xprintf

//#define _USE_XFUNC_OUT	1	/* 1: Use output functions */
#define	_CR_CRLF		1	/* 1: Convert \n ==> \r\n in the output char */
#define	_USE_LONGLONG	0	/* 1: Enable long long integer in type "ll". */
#define	_LONGLONG_t		long long	/* Platform dependent long long integer type */
#endif

#define DEBUG


#define UART_CR2_TE_MASK 0x08
#define UART_SR1_TDRE_MASK 0x80
#define UART_SR1_TC_MASK 0x40

/* Exported macro ------------------------------------------------------------*/
#ifdef DEBUG
#define DEBUG_PRINTF 1
#define LOG(fmt, ...)                                                                   \
    do                                                                                  \
    {                                                                                   \
        if (DEBUG_PRINTF == 1){                                                         \
            uint32_t tmp = SCB->DFSR;                                                   \
            printf("[D][%s\t%d]\t" fmt "\r\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); }\
    } while (0)


/*******************************************************************************
* Macro Name     : assert_param
* Description    : The assert_param macro is used for function's parameters check.
*                  It is used only if the library is compiled in DEBUG mode.
* Input          : - expr: If expr is false, it calls assert_failed function
*                    which reports the name of the source file and the source
*                    line number of the call that failed.
*                    If expr is true, it returns no value.
* Return         : None
*******************************************************************************/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
extern void assert_failed(uint8_t *file, uint32_t line);
extern void UART_Debug_Init(UART_TypeDef *UARTx, uint32_t pclk, uint32_t bound);
extern unsigned char Getchar(void);
extern void Putchar(int ch);
#else
#define assert_param(expr) ((void)0)
#endif /* DEBUG */

#endif
